//
//  HomepageTableViewCell.m
//  Frame
//
//  Created by 这是工作本 on 16/2/20.
//  Copyright © 2016年 这是工作本. All rights reserved.
//

#import "HomepageTableViewCell.h"

@interface HomepageTableViewCell () <UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, retain) UILabel *title;
@property (nonatomic, retain) UICollectionView *HcollectionV;

@end

@implementation HomepageTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}

-(void)cellFordata:(Homepage *)home
{
    
}


- (void)createSubview
{
 
    //红线
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(5 * ScreenWidth, 25 * ScreenWidth, 2 * ScreenWidth, 15 * ScreenHeigth)];
    imageV.image = [UIImage imageNamed:@"矩形-21@2x.png"];
    [self.contentView addSubview:imageV];
    
    //标题
    
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(imageV.frame.origin.x + 7 * ScreenWidth, imageV.frame.origin.y, 30 * ScreenWidth, 15 * ScreenHeigth)];
    self.title.textColor = [UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0];
    self.title.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    self.title.text = @"资讯";
    [self.contentView addSubview:self.title];

    
    //横向collectionView
    UICollectionViewFlowLayout *flowL_H = [[UICollectionViewFlowLayout alloc] init];
    //最小行间距
    flowL_H.minimumLineSpacing = 10 * ScreenWidth;
    //滚动方向
    flowL_H.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //单位大小
    flowL_H.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - 30 * ScreenWidth) / 4, 130 * ScreenHeigth);
    //与屏幕四边的间距
    flowL_H.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.HcollectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(10 * ScreenWidth, self.title.frame.origin.y + self.title.frame.size.height + 10 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, 130 * ScreenHeigth) collectionViewLayout:flowL_H];
    //隐藏指示条
    self.HcollectionV.showsHorizontalScrollIndicator = NO;
    //关掉滑动
    self.HcollectionV.scrollEnabled = YES;
    //关闭自动偏移
//    self.automaticallyAdjustsScrollViewInsets = NO;
    self.HcollectionV.backgroundColor = [UIColor colorWithRed:255 / 255.0  green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    self.HcollectionV.contentOffset = CGPointMake([[UIScreen mainScreen] bounds].size.width  / 4,  0);
    //签协议
    self.HcollectionV.delegate = self;
    self.HcollectionV.dataSource = self;
    //注册cell
    [self.HcollectionV registerClass:[HomepageCollectionViewCell class] forCellWithReuseIdentifier:@"horizontalCell"];
    self.HcollectionV.bounces = NO;
    self.HcollectionV.pagingEnabled = YES;
    
    [self.contentView addSubview:self.HcollectionV];

    
    
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomepageCollectionViewCell *home = [collectionView dequeueReusableCellWithReuseIdentifier:@"horizontalCell" forIndexPath:indexPath];
    
    
    return home;

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
